package com.example.administrator.yanfoxconn.activity;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TableRow;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.yanfoxconn.R;
import com.example.administrator.yanfoxconn.adapter.DNReformAdapter;
import com.example.administrator.yanfoxconn.adapter.YJExceZGRecordAdapter;
import com.example.administrator.yanfoxconn.bean.FileName;
import com.example.administrator.yanfoxconn.bean.SelectModel;
import com.example.administrator.yanfoxconn.bean.YJExceMessage;
import com.example.administrator.yanfoxconn.constant.Constants;
import com.example.administrator.yanfoxconn.constant.FoxContext;
import com.example.administrator.yanfoxconn.constant.ImageCaptureManager;
import com.example.administrator.yanfoxconn.intent.PhotoPickerIntent;
import com.example.administrator.yanfoxconn.intent.PhotoPreviewIntent;
import com.example.administrator.yanfoxconn.utils.BaseActivity;
import com.example.administrator.yanfoxconn.utils.FileUtil;
import com.example.administrator.yanfoxconn.utils.HttpConnectionUtil;
import com.example.administrator.yanfoxconn.utils.HttpUtils;
import com.example.administrator.yanfoxconn.utils.ImageZipUtils;
import com.example.administrator.yanfoxconn.utils.ToastUtils;
import com.example.administrator.yanfoxconn.widget.MyGridView;
import com.example.administrator.yanfoxconn.widget.MyListView;
import com.example.administrator.yanfoxconn.widget.SwipeListViewOne;
import com.example.administrator.yanfoxconn.widget.TouchImageView;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import org.json.JSONArray;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @Description 营建异常记录詳情界面
 * @Author song
 * @Date 7/22/21 7:55 PM
 */
public class YJExceDetailActivity extends BaseActivity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener  {
    @BindView(R.id.btn_title_left)
    Button btnBack;//返回
    @BindView(R.id.tv_title)
    TextView tvTitle;//標題
    @BindView(R.id.btn_title_right)
    Button btnUp;//提交

    @BindView(R.id.tv_build)
    TextView tvBuild;//棟別
    @BindView(R.id.tv_position)
    TextView tvPosition;//位置
    @BindView(R.id.tv_dep)
    TextView tvDep;//使用單位
    @BindView(R.id.tv_p_id)
    TextView tvPId;//聯繫人工號
    @BindView(R.id.tv_p_name)
    TextView tvPName;//聯繫人姓名
    @BindView(R.id.tv_p_phone)
    TextView tvPPhone;//聯繫電話
    @BindView(R.id.tv_type)
    TextView tvType;//系統類別
    @BindView(R.id.tv_desp)
    TextView tvDesp;//異常描述
    @BindView(R.id.tv_reason)
    TextView tvReason;//異常原因
    @BindView(R.id.ll_get_image)
    GridLayout llGetImage;//異常圖片
    @BindView(R.id.tr_pg_id)
    TableRow trPgId;//派工單號
    @BindView(R.id.tv_pg_id)
    TextView tvPGId;
    @BindView(R.id.ll_is_pg)
    LinearLayout llIsPg;
    @BindView(R.id.rg_pg)
    RadioGroup rgPg;
    @BindView(R.id.rb_pg_y)
    RadioButton rbPGY;
    @BindView(R.id.rb_pg_n)
    RadioButton rbPGN;
    @BindView(R.id.rg_j)
    RadioGroup rgJ;
    @BindView(R.id.rb_1)
    RadioButton rbJ1;
    @BindView(R.id.rb_2)
    RadioButton rbJ2;
    @BindView(R.id.iv_empty)
    ImageView ivEmpty;//空白图片占位
    @BindView(R.id.gv_photo)
    MyGridView gridView;//图片显示区域
    @BindView(R.id.ll_pg_id)
    LinearLayout llPGID;//派工單號
    @BindView(R.id.et_pg_id)
    EditText etPGID;//派工單號
    @BindView(R.id.et_treat_desp)
    EditText etDescribe;//描述
    @BindView(R.id.ll_is_end_gone)
    LinearLayout llIsEndGone;//


    @BindView(R.id.lv_record)
    MyListView lvRecord;//整改記錄

    private YJExceMessage mCheckExceMsg,mExceMsg;
    private YJExceZGRecordAdapter yjExceZGRecordAdapter;
    private List<YJExceMessage> mExceMsgList;
    private static final int REQUEST_CAMERA_CODE = 11;
    private static final int REQUEST_PREVIEW_CODE = 22;
    private ArrayList<String> imagePaths = null;//圖片未壓縮地址
    private ImageCaptureManager captureManager; // 相机拍照处理类
    private GridAdapter gridAdapter;
    String exce_id,dim_id,yj_id,exceStatue,isPG,flag;
    private String userCode;
    private String userName;
    YJExceDetailActivity context = this;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yj_exce_detail);
        ButterKnife.bind(this);

        tvTitle.setText("異常詳情");
        btnUp.setVisibility(View.VISIBLE);
        btnUp.setOnClickListener(this);
        btnBack.setOnClickListener(this);
        ivEmpty.setOnClickListener(this);
        rgJ.setOnCheckedChangeListener(this);
        rgPg.setOnCheckedChangeListener(this);
        rbJ1.setOnClickListener(this);
        rbJ2.setOnClickListener(this);
        rbPGN.setOnClickListener(this);
        rbPGY.setOnClickListener(this);
        rbJ1.setChecked(true);
        exceStatue="1";
        rbPGN.setChecked(true);
        isPG="N";
        mCheckExceMsg = ((YJExceMessage)getIntent().getSerializableExtra("mCheckExceMsg"));
        yj_id = getIntent().getStringExtra("id");
        flag = getIntent().getStringExtra("flag");
        if (flag.equals("end")){

            btnUp.setText("結案");
            llIsEndGone.setVisibility(View.GONE);
        }else{

            btnUp.setText("提交");
        }
        getMessage();

        int cols = getResources().getDisplayMetrics().widthPixels / getResources().getDisplayMetrics().densityDpi;
        cols = cols < 4 ? 4 : cols;
        gridView.setNumColumns(cols);

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (position == imagePaths.size()) {
                    PhotoPickerIntent intent = new PhotoPickerIntent(YJExceDetailActivity.this);
                    intent.setSelectModel(SelectModel.MULTI);
                    intent.setShowCarema(true); // 是否显示拍照
                    intent.setMaxTotal(3); // 最多选择照片数量，默认为3
                    intent.setSelectedPaths(imagePaths); // 已选中的照片地址， 用于回显选中状态
                    startActivityForResult(intent, REQUEST_CAMERA_CODE);
                } else {
                    PhotoPreviewIntent intent = new PhotoPreviewIntent(YJExceDetailActivity.this);
                    intent.setCurrentItem(position);
                    intent.setPhotoPaths(imagePaths);
                    startActivityForResult(intent, REQUEST_PREVIEW_CODE);
                }
            }
        });
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {

            switch (requestCode) {
                // 选择照片
                case REQUEST_CAMERA_CODE:
                    loadAdpater(data.getStringArrayListExtra(PhotoPickerActivity.EXTRA_RESULT));
                    break;
                // 预览
                case REQUEST_PREVIEW_CODE:
                    loadAdpater(data.getStringArrayListExtra(PhotoPreviewActivity.EXTRA_RESULT));
                    break;
                // 调用相机拍照
                case ImageCaptureManager.REQUEST_TAKE_PHOTO:
                    if (captureManager.getCurrentPhotoPath() != null) {
                        captureManager.galleryAddPic();
                        ArrayList<String> paths = new ArrayList<>();
                        paths.add(captureManager.getCurrentPhotoPath());
                        loadAdpater(paths);
                        Log.e("==========", paths.get(1));
                    }
                    break;
            }
        }
    }
    private void loadAdpater(ArrayList<String> paths) {

        if (imagePaths == null) {
            imagePaths = new ArrayList<>();
        }
        imagePaths.clear();
        imagePaths.addAll(paths);

        if (paths.size() > 0) {
            ivEmpty.setVisibility(View.GONE);
        } else {
            ivEmpty.setVisibility(View.VISIBLE);
        }

        try {
            JSONArray obj = new JSONArray(imagePaths);
            Log.e("--", obj.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (gridAdapter == null) {
            gridAdapter = new GridAdapter(imagePaths);
            gridView.setAdapter(gridAdapter);
            Log.e("----------------", "ddd==" + imagePaths.size());
        } else {
            gridAdapter.notifyDataSetChanged();
        }

    }
    private class GridAdapter extends BaseAdapter {
        private ArrayList<String> listUrls;

        public GridAdapter(ArrayList<String> listUrls) {
            this.listUrls = listUrls;
        }

        @Override
        public int getCount() {
            if (listUrls.size() == 3) {
                return 3;
            } else {
                return listUrls.size() + 1;
            }

        }

        @Override
        public String getItem(int position) {
            return listUrls.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imageView;
            if (convertView == null) {
                convertView = getLayoutInflater().inflate(R.layout.item_image, null);
                imageView = (ImageView) convertView.findViewById(R.id.imageView);
                convertView.setTag(imageView);
                // 重置ImageView宽高
//                LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(columnWidth, columnWidth);
//                imageView.setLayoutParams(params);
            } else {
                imageView = (ImageView) convertView.getTag();
            }
            if (position == listUrls.size()) {
                imageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.mipmap.icon_addpic_unfocused));
                if (position == 3) {
                    imageView.setVisibility(View.GONE);
                }
            } else {
                Glide.with(YJExceDetailActivity.this)
                        .load(new File(getItem(position)))
                        .placeholder(R.mipmap.default_error)
                        .error(R.mipmap.default_error)
                        .centerCrop()
                        .crossFade()
                        .into(imageView);
            }
            return convertView;
        }
    }
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_title_left:
                finish();
                break;
            case R.id.btn_title_right:
                if (flag.equals("end")){
                    aboutAlert("確定要結案嗎", 111);
                }else {
                    aboutAlert(getResources().getString(R.string.update_confirm), Constants.MESSAGE_UP);
                }
                break;
            case R.id.iv_empty:
                PhotoPickerIntent intent = new PhotoPickerIntent(YJExceDetailActivity.this);
                intent.setSelectModel(SelectModel.MULTI);
                intent.setShowCarema(true); // 是否显示拍照
                intent.setMaxTotal(3); // 最多选择照片数量，默认为3
                intent.setSelectedPaths(imagePaths); // 已选中的照片地址， 用于回显选中状态
                startActivityForResult(intent, REQUEST_CAMERA_CODE);
                break;
        }
    }
    private void getMessage(){

        showDialog();

        final String url = Constants.HTTP_YJ_GET_EXCE_DETAIL +"?yj_id="+yj_id ;
        Log.e("-----------", "url==" + url);
        new Thread() {
            @Override
            public void run() {
                //把网络访问的代码放在这里
                String result = HttpUtils.queryStringForGet(url);
                dismissDialog();
                Gson gson = new Gson();
                if (result != null) {
                    Log.e("---------", "result==fff===" + result);
                    JsonObject jsonObject = new JsonParser().parse(result).getAsJsonObject();
                    String errCode = jsonObject.get("errCode").getAsString();
                    if (errCode.equals("200")) {
                        JsonObject jsonObject1 = jsonObject.getAsJsonObject("data");

                        JsonObject jsonObjectExce = jsonObject1.getAsJsonObject("exceData");
                        mExceMsg = gson.fromJson(jsonObjectExce, YJExceMessage.class);

                        JsonArray array = jsonObject1.get("treatData").getAsJsonArray();
                        mExceMsgList = new ArrayList<YJExceMessage>();
                        for (JsonElement type : array) {
                            YJExceMessage humi = gson.fromJson(type, YJExceMessage.class);
                            mExceMsgList.add(humi);
                        }

                        Message message = new Message();
                        message.what = Constants.MESSAGE_SET_TEXT;
                        message.obj = jsonObject.get("errMessage").getAsString();
                        mHandler.sendMessage(message);

                    } else{
                        Log.e("-----------", "result==" + result);
                        Message message = new Message();
                        message.what = Constants.MESSAGE_TOAST;
                        message.obj = jsonObject.get("errMessage").getAsString();
                        mHandler.sendMessage(message);
                    }
                }else{
                    Message message = new Message();
                    message.what = Constants.MESSAGE_NETMISTAKE;
                    mHandler.sendMessage(message);
                    finish();
                }
            } }.start();
    }

    //提交前檢查
    private void check() {

        final String url = Constants.HTTP_YJ_EXCE_HANDLE; //此處寫上自己的URL

        JsonObject object = new JsonObject();


        object.addProperty("yj_id",yj_id);
        object.addProperty("exce_statue", exceStatue);
        object.addProperty("treat_desp", etDescribe.getText().toString());
        object.addProperty("treat_people_id",FoxContext.getInstance().getLoginId());
        object.addProperty("treat_people_name", FoxContext.getInstance().getName());
            object.addProperty("is_pg", isPG);
            object.addProperty("pg_no", etPGID.getText().toString());


         if (imagePaths == null || imagePaths.size() == 0) {
            ToastUtils.showShort(this, "請拍照或選擇圖片");
        }else{
            JsonArray photoArray = new JsonArray();

            for (int i = 0; i < imagePaths.size(); i++) {

                final String pic_path = imagePaths.get(i);
                String sign_dir = Environment.getExternalStorageDirectory() + File.separator + "YanFoxconn" + File.separator + "Photos";
                String _path =  sign_dir + File.separator  + System.currentTimeMillis() +i+ ".jpg";
//                调用压缩图片的方法，返回压缩后的图片path
                final String compressImage = ImageZipUtils.compressImage(pic_path, _path, 50);
                String picBase64Code = ImageZipUtils.imageToBase64(compressImage);
                //Log.e("---picBase64Code---", "===="+ picBase64Code);
                JsonObject jsonObject1 = new JsonObject();
                jsonObject1.addProperty("file", picBase64Code);
                photoArray.add(jsonObject1);
            }
            object.add("photo", photoArray);
            Log.e("-----object------",  object.toString());


            //開啟一個新執行緒，向伺服器上傳資料
            new Thread() {
                public void run() {
                    //把网络访问的代码放在这里
                    try {
                        showDialog();
                        Log.e("---------", "==fff===" + url);
                        String result = HttpConnectionUtil.doPostJsonObject(url, object);
                        if (result != null) {
                            dismissDialog();
                            Log.e("---------", "result==fff===" + result);
                            JsonObject jsonObject = new JsonParser().parse(result).getAsJsonObject();
                            String errCode = jsonObject.get("errCode").getAsString();
                            if (errCode.equals("200")) {
                                Message message = new Message();
                                message.what = Constants.MESSAGE_TOAST;
                                message.obj = jsonObject.get("errMessage").getAsString();
                                mHandler.sendMessage(message);

                            } else{
                                Message message = new Message();
                                message.what = Constants.MESSAGE_TOAST;
                                message.obj = jsonObject.get("errMessage").getAsString();
                                mHandler.sendMessage(message);
                            }
                        }else{
                            Message message = new Message();
                            message.what = Constants.MESSAGE_NETMISTAKE;
                            mHandler.sendMessage(message);
                            finish();
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }finally {
                        FileUtil.deletePhotos(YJExceDetailActivity.this);
                    }
                }
            }.start();
        }


    }

    /**
     * 結案
     */
    private void setEnd(){
        showDialog();
        final String url = Constants.HTTP_YJ_EXCE_FINISH  ;
        Log.e("-----------", "url==" + url);

        JsonObject object = new JsonObject();

        object.addProperty("yj_id",yj_id);
        object.addProperty("exce_statue", "3");
        object.addProperty("exce_end_zg_id",FoxContext.getInstance().getLoginId());
        object.addProperty("exce_end_zg_name", FoxContext.getInstance().getName());

            //開啟一個新執行緒，向伺服器上傳資料
            new Thread() {
                public void run() {
                    //把网络访问的代码放在这里
                    try {
                        Log.e("---------", "==fff===" + url);
                        String result = HttpConnectionUtil.doPostJsonObject(url, object);
                        if (result != null) {
                            dismissDialog();
                            Log.e("---------", "result==fff===" + result);
                            JsonObject jsonObject = new JsonParser().parse(result).getAsJsonObject();
                            String errCode = jsonObject.get("errCode").getAsString();
                            if (errCode.equals("200")) {
                                Message message = new Message();
                                message.what = MESSAGE_TOAST;
                                message.obj = jsonObject.get("errMessage").getAsString();
                                mHandler.sendMessage(message);

                            } else{
                                Message message = new Message();
                                message.what = MESSAGE_TOAST;
                                message.obj = jsonObject.get("errMessage").getAsString();
                                mHandler.sendMessage(message);
                            }
                        }else{
                            Message message = new Message();
                            message.what = Constants.MESSAGE_NETMISTAKE;
                            mHandler.sendMessage(message);
                            finish();
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }finally {
                        FileUtil.deletePhotos(YJExceDetailActivity.this);
                    }
                }
            }.start();

    }
private final int MESSAGE_TOAST=11111;
    Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MESSAGE_TOAST://Toast彈出
                    ToastUtils.showLong(YJExceDetailActivity.this, msg.obj.toString());
                    finish();
                    break;
                case Constants.MESSAGE_TOAST://Toast彈出
                    aboutAlert(msg.obj.toString(),Constants.MESSAGE_TOAST);
//                    ToastUtils.showLong(CrossScanActivity.this, msg.obj.toString());
//                    finish();
                    break;
                case Constants.MESSAGE_NETMISTAKE://Toast彈出
                    ToastUtils.showLong(YJExceDetailActivity.this,R.string.net_mistake);
                    break;
                case Constants.MESSAGE_SET_TEXT://text賦值
                    tvBuild.setText(mExceMsg.getYj_building());
                    tvPosition.setText(mExceMsg.getYj_position());
                    tvDep.setText(mExceMsg.getYj_dep());
                    tvPId.setText(mExceMsg.getYj_people_id());
                    tvPName.setText(mExceMsg.getYj_people_name());
                    tvPPhone.setText(mExceMsg.getYj_phone());
                    tvType.setText(mExceMsg.getYj_type_id());
                    tvDesp.setText(mExceMsg.getExce_desp());
                    tvReason.setText(mExceMsg.getExce_reason());
                    if (mExceMsg.getIs_pg().equals("Y")){
                        trPgId.setVisibility(View.VISIBLE);
                        tvPGId.setText(mExceMsg.getPg_no());
                        llIsPg.setVisibility(View.GONE);
                        isPG="";
                    }

                    List<FileName> photos = mExceMsg.getPhoto();
                    for (int i=0;i<photos.size();i++){
                        TouchImageView imageView = new TouchImageView(YJExceDetailActivity.this);
//                        ImageView imageView = new ImageView(ZhiyinshuiExceDetailActivity.this);
                        String imgStr = photos.get(i).getEXCE_FILENAME1();
                        Log.e("------imgStr-----", "======"+imgStr);
                        byte[] decode = Base64.decode(imgStr, Base64.DEFAULT);
                        Bitmap bitmap = BitmapFactory.decodeByteArray(decode, 0, decode.length);
                        imageView.setAdjustViewBounds(true);
                        imageView.setScaleType(ImageView.ScaleType.CENTER);
                        imageView.setImageBitmap(bitmap);
                        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(200, 200);
                        layoutParams.setMargins(10, 10, 10, 10);
                        imageView.setLayoutParams(layoutParams);

                        //設置點擊放大事件
                        imageView.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                int[] location = new int[2];
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                                    Rect frame = new Rect();
                                    getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
                                    int statusBarHeight = frame.top;

                                    view.getLocationOnScreen(location);
                                    location[1] += 0;
                                } else {
                                    view.getLocationOnScreen(location);
                                }
                                view.invalidate();
                                int width = view.getWidth();
                                int height = view.getHeight();

                                Intent intent = new Intent(YJExceDetailActivity.this, BigImageActivity.class);
                                Bundle b = new Bundle();
                                b.putString(BigImageActivity.QR_IMAGE_URL, imgStr);
                                intent.putExtras(b);
//                                intent.putExtra(BigImageActivity.PHOTO_SELECT_POSITION,);
                                intent.putExtra(BigImageActivity.PHOTO_SELECT_X_TAG, location[0]);
                                intent.putExtra(BigImageActivity.PHOTO_SELECT_Y_TAG, location[1]);
                                intent.putExtra(BigImageActivity.PHOTO_SELECT_W_TAG, width);
                                intent.putExtra(BigImageActivity.PHOTO_SELECT_H_TAG, height);
                                startActivity(intent);
                                overridePendingTransition(0, 0);
                            }
                        });
                        llGetImage.addView(imageView);
                    }

                    if (mExceMsgList!=null&&mExceMsgList.size()!=0){
                        yjExceZGRecordAdapter = new YJExceZGRecordAdapter(context, mExceMsgList);
                        lvRecord.setAdapter(yjExceZGRecordAdapter);
                        yjExceZGRecordAdapter.setOnClickListener(new YJExceZGRecordAdapter.OnClickListener() {
                            @Override
                            public void onclick(int paramInt1, int paramInt2, View view) {
                                int[] location = new int[2];
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                                    Rect frame = new Rect();
                                    getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
                                    int statusBarHeight = frame.top;

                                    view.getLocationOnScreen(location);
                                    location[1] += 0;
                                } else {
                                    view.getLocationOnScreen(location);
                                }
                                view.invalidate();
                                int width = view.getWidth();
                                int height = view.getHeight();

                                Intent intent = new Intent(YJExceDetailActivity.this, BigImageActivity.class);
                                Bundle b = new Bundle();
                                b.putString(BigImageActivity.QR_IMAGE_URL, mExceMsgList.get(paramInt1).getPhoto().get(paramInt2).getEXCE_FILENAME1());
                                intent.putExtras(b);
//                                intent.putExtra(BigImageActivity.PHOTO_SELECT_POSITION,);
                                intent.putExtra(BigImageActivity.PHOTO_SELECT_X_TAG, location[0]);
                                intent.putExtra(BigImageActivity.PHOTO_SELECT_Y_TAG, location[1]);
                                intent.putExtra(BigImageActivity.PHOTO_SELECT_W_TAG, width);
                                intent.putExtra(BigImageActivity.PHOTO_SELECT_H_TAG, height);
                                startActivity(intent);
                                overridePendingTransition(0, 0);
                            }
                        });
                    }

                    break;
                case Constants.MESSAGE_UP://提交響應
                    worningAlert(msg.obj.toString(),Constants.MESSAGE_TOAST);
//                    ToastUtils.showLong(CrossScanActivity.this, msg.obj.toString());
                    break;
                case Constants.MESSAGE_JUMP://跳轉維護異常界面
                    worningAlert(msg.obj.toString(),Constants.MESSAGE_JUMP);
                    break;
            }
            super.handleMessage(msg);
        }
    };

    private void aboutAlert(String msg, final int type) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("提示信息")
                .setMessage(msg)
                .setCancelable(false)
                .setPositiveButton("確認", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        // TODO Auto-generated method stub
                        if (type==Constants.MESSAGE_TOAST){
                            finish();
                        }else  if (type==111){
                            setEnd();
                        }else if(type==Constants.MESSAGE_UP){
                            if (imagePaths==null||imagePaths.size()==0){
                                ToastUtils.showLong(YJExceDetailActivity.this,"请上传異常照片！");
                            }else if (isPG.equals("Y")&&etPGID.getText().toString().equals("")){
                                ToastUtils.showShort(YJExceDetailActivity.this,"請填寫派工單號！");
                            }else if (etDescribe.getText().toString().equals("")){
                                ToastUtils.showShort(YJExceDetailActivity.this,"請填寫處理結果！");
                            }else{
                            check();
                            btnUp.setClickable(false);
                            btnUp.setVisibility(View.GONE);
                            }
                        }
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }
    private void worningAlert(String msg, final int type) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("提示信息")
                .setMessage(msg)
                .setCancelable(false)
                .setPositiveButton("確認", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        // TODO Auto-generated method stub
                        if (type==Constants.MESSAGE_TOAST){
                            finish();
                        }else if (type==Constants.MESSAGE_JUMP){

//                            Intent intent = new Intent(ZhiyinshuiCheckActivity.this,ZhiyinshuiMaintenanceActivity.class);
//                            intent.putExtra("dim_id",mMsgList.get(0).getDim_id());
//                            startActivity(intent);
//                            ToastUtils.showShort(ZhiyinshuiCheckActivity.this, "跳轉異常界面!");
                        }
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (group.getCheckedRadioButtonId()) {
            case R.id.rb_pg_y:
                isPG = "Y";
                llPGID.setVisibility(View.VISIBLE);
                break;
            case R.id.rb_pg_n:
                isPG = "N";
                llPGID.setVisibility(View.GONE);
                break;
                case R.id.rb_1:
                exceStatue = "1";
                break;
                case R.id.rb_2:
                    exceStatue = "2";
                break;
        }
    }
}
